<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">   
    <title>test.jsp</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

    <style type="text/css">
	<!--
	#usersDisp {
		position:absolute;
		width:200px;
		height:214px;
		z-index:1;
		left: 9px;
		top: 56px;
	}
	#msgInp {
		position:absolute;
		width:244px;
		height:130px;
		z-index:2;
		left: 596px;
		top: 44px;
	}
	#msgDisp {
		position:absolute;
		width:435px;
		height:2181px;
		z-index:3;
		left: 602px;
		top: 304px;
	}
	-->
    </style>
    <script src="jquery-1.7.2.js" type="text/javascript"></script>
	<script type="text/javascript">
		function sendMessage(){
			//alert(new Date(1351313548187).toLocaleTimeString());		
			$.post(
				"postPubMessages",
				{
					text:$("#text").val(),	
					username:$("#username").text()			
				},
				function(data,status){
					/*$("#chats").append(data.text+"<br>");*/
					$("#text").val("");
				}
			);
		}
		
	
		function getMessage(){
			$.get(
				"loadPubMessages",
				{},
				function(data,status){
					//alert(status);
					if(status == 'success'){		
						$.each(data.loadPubMessages,function(i,item){
							$("#dialogue").append(item.text+"\n"+"       "+item.user.username+"   " +item.date+"\n\n")}
						);
					}
				}
			);
			
			setTimeout('getMessage()',1000);		
		}
		$(getMessage());
	</script> 
  </head>
  
  <body>
 	<div id="username"><%=session.getAttribute("username")%></div>

    <div id="usersDisp">
	  	<table width="465" height="92" border="0">
	        <tr>
	          <td>用户ID</td>
	          <td>用户名</td>
			  <td></td>	 
	        </tr>
	       
		    <s:iterator value="#request.allUser" var="user">	
				<tr>
					  <td>
					  <s:property value="#user.getUserId()"/>
			  		  </td>
			 	  
				      <td>		 
				      <s:property value="#user.getUsername()"/>
			  		  </td>
			  		
					  <td>		      
				      </td>    
				</tr>
			</s:iterator>
		</table>
    </div>
	
 	<div id="chats"></div>
 	
    <div id="msgInp">
	    <h3>输入区</h3>
	    <textarea name="textarea" cols="60" rows="8" id="text"></textarea>
	    <input name="submit" type="submit" id="send" onClick="sendMessage();" value="发送"/> 
 	</div>
 	
    <div id="msgDisp">
        <h3>显示区</h3>
        <textarea name="textarea2" cols="60" rows="28" id="dialogue"></textarea>    
    </div>
    
  </body>
</html>